<template>
	<view class="pre-order">
		<!-- <uni-search-bar @confirm="1" @input="1" /> -->
		<!-- <uni-search-bar @confirm="search" :focus="true" v-model="searchValue" @blur="blur" @focus="focus" @input="input"
						@cancel="cancel" @clear="clear">
		</uni-search-bar> -->
		<uni-search-bar @confirm="confirm" @input="input"></uni-search-bar>
		<view class="title" v-if="preorderList.length">
			预约记录
		</view>
		<view class="list">
			<OrderItem v-for="item in preorderList" :key="item.id" :item="item" @click="goDetail(item.id)"></OrderItem>
		</view>
		<view class="title" v-if="newsList.length">
			动态记录
		</view>
		<view class="re-item" v-for="item in newsList" :key="item.id" @click="goDetails(item.id)">
			<image :src="item.cover" mode=""></image>
			<view class="right">
				<view class="title">
					{{item.title}}
				</view>
				<text class="content">
					{{ item.content }}
				</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { GetFavList,GetPreOrderListByKeywords,GetLookList } from '../../api/index.js'
	export default {
		data() {
			return {
				preorderList:[],
				newsList:[]
			};
		},
		onLoad() {
			this.getFavList(),
			this.getLookList()
		},
		methods:{
			async getFavList(){
				// let userinfo = JSON.parse(uni.getStorageSync('userinfo'||''))
				// console.log(userinfo,'userinfo')
				// const {data:res} = await GetFavList(userinfo.id)
				// console.log(res,'favlist')
				// res.data.forEach(item=>{
				// 	item.disc = item.disc.split('，')
				// })
				// if(res.status==0){
				// 	this.preorderList = res.data
				// }
			},
			async getLookList(){
				let userinfo = JSON.parse(uni.getStorageSync('userinfo'||''))
				console.log(userinfo,'userinfo')
				const {data:res} = await GetLookList(userinfo.id)
				console.log(res,'looklist')
				// res.data.forEach(item=>{
				// 	item.disc = item.disc.split('，')
				// })
				
				if(res.status==0){
					res.data.favlist.forEach(item=>{
					item.disc = item.disc.split('，')
					})
					this.preorderList = res.data.favlist
					this.newsList = res.data.newslist
				}
			},
			async confirm(v){
				console.log(v,'v')
				const { data:res } = await GetPreOrderListByKeywords(v.value)
				console.log(res,'2334rrr')
				res.data.forEach(item=>{
					item.disc = item.disc.split('，')
				})
				this.preorderList = res.data
				if(!v){
					this.getFavList()
				}
			},
			input(v){
				console.log(v,'33')
			},
			goDetail(id){
				console.log(id)
				uni.navigateTo({
					url:'/subPackage/PreOrderDetail/PreOrderDetail?id='+id
				})
			},
			// 跳转详情
			goDetails(id){
				console.log(id)
				uni.navigateTo({
					url:'/subPackage/NewsDetail/NewsDetail?id='+id
				})
			},
		}
	}
</script>

<style lang="scss">
.pre-order{
	width: 100%;
	// border: 1px solid #f00;
	// display: flex;
	padding: 20rpx;
	padding-top: 0;
	box-sizing: border-box;
	.list{
		width: 100%;
		// border: 1px solid #000;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		
		
	}
	.re-item{
		width: 100%;
		// border: 1px solid #000;
		display: flex;
		// flex-wrap: wrap;
		margin: 20rpx 0;
		image{
			width: 300rpx;
			height: 200rpx;
			margin-right: 20rpx;
			border-radius: 8rpx;
		}
		.right{
			width: 70%;
			.content{
				text-overflow: ellipsis;
				// text-overflow: -o;
				overflow: hidden;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical;
			}
			
		}
	}
}
</style>
